<?php

/**
 * O2O团购PC版本
 * ============================================================================
 * * 版权所有 2009-2016 郑州司科计算机科技有限公司，并保留所有权利。
 * 购买网址: http://www.jzphp.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
  * 咨询电话：400-823-0371 QQ：313999875
 * ============================================================================
 * $Author: zzsike $
 * $Time 2016-02-03 sammy $
*/


require_once(dirname(dirname(dirname(__FILE__))) . '/app.php');

need_manager();
need_auth('market');

$id = abs(intval($_GET['id']));
$partner = Table::Fetch('partner', $id);




if($partner['city_id']){
	$areas=DB::LimitQuery('category',array(
		'condition'=>array(
			'zone'=>'area',
			'fid'=>$partner['city_id'],
		),
		'order'=>'order by sort_order'
	));
	$areas=Utility::OptionArray($areas,'id','name');
}

$long=0;
$lat=0;


if ( $_POST && $id==$_POST['id'] && $partner) {
	$table = new Table('partner', $_POST);
	$table->SetStrip('location', 'other');
	$table->group_id = abs(intval($table->group_id));
	$table->city_id = abs(intval($table->city_id));
	$table->open = (strtoupper($table->open)=='Y') ? 'Y' : 'N';
	$table->brands = (strtoupper($table->brands)=='Y') ? 'Y' : 'N';
	$table->display = (strtoupper($table->display)=='Y') ? 'Y' : 'N';
	$table->business_team_edit = (strtoupper($table->business_team_edit)=='Y') ? 'Y' : 'N';
	$table->business_order_edit = (strtoupper($table->business_order_edit)=='Y') ? 'Y' : 'N';
	$table->image = upload_image('upload_image', $partner['image'], 'team', true);
	$table->image1 = upload_image('upload_image1', $partner['image1'], 'team');
	$table->image2 = upload_image('upload_image2', $partner['image2'], 'team');
	if($_POST['longlat']!=''){
		list($long,$lat)=explode(',',$_POST['longlat']);
		$table->longitude=$long;
		$table->latitude=$lat;
	}
	$up_array = array(
			'username', 'title', 'bank_name', 'bank_user', 'bank_no',
			'location', 'other', 'homepage', 'contact', 'mobile', 'phone',
			'address', 'group_id', 'open', 'city_id', 'display',
			'image', 'image1', 'image2', 'longlat','longitude','latitude', 'head','yy_time','area_id','brands','server','business_team_edit','business_order_edit'
			);

	if ($table->password ) {
		$table->password = ZPartner::GenPassword($table->password);
		$up_array[] = 'password';
	}
	$flag = $table->update( $up_array );
	if ( $flag ) {
		if($long!=$partner['longitude'] || $lat!=$partner['latitude']){
			$sql="update `team` set latitude=$lat,longitude=$long where partner_id=$id";
			DB::Query($sql);
		}
		Session::Set('notice', '修改商户信息成功');
		redirect( WEB_ROOT . "/manage/partner/edit.php?id={$id}");
	}
	Session::Set('error', '修改商户信息失败');
	$partner = $_POST;
}

include template('manage_partner_edit');
